
/* Generated by Interface Builder */

#import "MyObject.h"
#import "Julian.h"
#import <appkit/Slider.h>
#import <appkit/Button.h>
#import <appkit/TextField.h>
#import <dpsclient/wraps.h>
#import <stdio.h>
#import <stdlib.h>


#define MONTH	0
#define DAY 	1
#define YEAR	2
#define HOUR	3
#define MIN		4
#define SEC		5

char *dowStr[] = {"","Sun","Mon","Tues","Wed","Thur","Fri","Sat"};

@implementation MyObject
- init
{
char *aStr;
	[super init];
	aStr = (char*) malloc(15);
	currentDay = 1;
	currentMonth = 1;
	currentYear = 1991;
	currentHour = 0;
	currentMin = 0;
	currentSec = 0;
	sprintf(aStr,"%li",[Julian julianDay:currentDay: currentMonth: currentYear]);
	[julianField setStringValue:aStr];
	return self;
}



- sliderControl:sender
{
int i;
long julianDate;
double julianDay;
int operator;
char julianStr[37];
char iStr[5];
BOOL state;
int calDay,calMonth,calYear;

    operator = [sender selectedTag];
	 i = [sender intValue];
	 sprintf(iStr,"%i",i);
	 
    switch(operator){
	 	case 	MONTH:	
			currentMonth = i;
			[monthField setStringValue:iStr];
			break;																
		case 	DAY:
			currentDay = i; 
			[dayField setStringValue:iStr];
			break;
		case	YEAR:
			currentYear = i;
			[yearField setStringValue:iStr];
			break;
	 	case 	HOUR:	
			currentHour = i;
			[hourField setStringValue:iStr];
			break;	
																		
		case 	MIN:
			currentMin = i; 
			[minField setStringValue:iStr];
			break;
		case	SEC:
			currentSec = i;
			[secField setStringValue:iStr];
			break;
	 }
	 
	julianDate = [Julian julianDay:currentDay:currentMonth:currentYear];
	julianDay = [Julian julianDay		: currentDay
												: currentMonth
												: currentYear
												: currentHour
												: currentMin
												: currentSec
												];
	sprintf(julianStr,"%li",julianDate);
	[julianField setStringValue:julianStr];
	
	sprintf(julianStr,"%f",julianDay);
	[julianDayField setStringValue:julianStr];
	
	[dowField setStringValue:dowStr[ [Julian dow:julianDate]]];
	sprintf(julianStr,"%03i",[Julian doy:currentDay
													:currentMonth
													:currentYear]);
	[doyField setStringValue:julianStr];
	
	sprintf(julianStr,"%03i",(int) ([Julian wkd:currentDay
													:currentMonth
													:currentYear] - 
													[Julian wkd:1
													:1
													:currentYear]));
	[wkdField setStringValue:julianStr];
	
	state = [Julian validDay:currentDay:currentMonth:currentYear];
	if( state == 0 )
	{
		[validField setStringValue:"INVALID"];
	}
	else
	{
		[validField setStringValue:"OK"];
	}
	// now reconvert to jday
	[Julian calendarDay:julianDate:&calDay:&calMonth:&calYear];
	sprintf(julianStr,"%i",calDay);
	[resultDayField setStringValue:julianStr];
	sprintf(julianStr,"%i",calMonth);
	[resultMonthField setStringValue:julianStr];
	sprintf(julianStr,"%i",calYear);
	[resultYearField setStringValue:julianStr];
 	return self;
}


@end
